package Views;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

import Controllers.ClientController;


public class ClientIHM extends JFrame{
	private static final long serialVersionUID = 1L;
	private ClientController controller;
	private JPanel panneau;
	private JComboBox listeServices;
	
	public ClientIHM(ClientController controller) {
		this.controller = controller;
	}

	public void construireIHM(Object[] services) {
		panneau = new JPanel();
		this.getContentPane().add(BorderLayout.CENTER, panneau);

		listeServices = new JComboBox(services);
		this.getContentPane().add(BorderLayout.NORTH, listeServices);

		listeServices.addActionListener(new ListenList());

		this.setSize(500,500);
		this.setVisible(true);
	}
	
	public void afficherService(JPanel panel) {
		panneau.removeAll();
		panneau.add(panel);
		panneau.validate();
		panneau.repaint();
	}
	
	public class ListenList implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// accéder au service sélectionné

			Object selection =  listeServices.getSelectedItem();
			controller.chargerService(selection);
		}
	}
}